package o;

import java.io.EOFException;
import java.io.IOException;
import java.util.zip.Inflater;

public final class fxk implements fxw {
    private int ˋ;
    private final Inflater ˎ;
    private boolean ˏ;
    private final fxg ॱ;

    fxk(fxg o_fxg, Inflater inflater) {
        if (o_fxg == null) {
            throw new IllegalArgumentException("source == null");
        } else if (inflater == null) {
            throw new IllegalArgumentException("inflater == null");
        } else {
            this.ॱ = o_fxg;
            this.ˎ = inflater;
        }
    }

    public long ˊ(fxi o_fxi, long j) throws IOException {
        if (j < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j);
        } else if (this.ˏ) {
            throw new IllegalStateException("closed");
        } else if (j == 0) {
            return 0;
        } else {
            boolean ˋ;
            do {
                ˋ = ˋ();
                try {
                    fxt ˏ = o_fxi.ˏ(1);
                    int inflate = this.ˎ.inflate(ˏ.ˏ, ˏ.ˋ, (int) Math.min(j, (long) (8192 - ˏ.ˋ)));
                    if (inflate > 0) {
                        ˏ.ˋ += inflate;
                        o_fxi.ˎ += (long) inflate;
                        return (long) inflate;
                    } else if (this.ˎ.finished() || this.ˎ.needsDictionary()) {
                        ॱ();
                        if (ˏ.ˎ == ˏ.ˋ) {
                            o_fxi.ॱ = ˏ.ˎ();
                            fxs.ˊ(ˏ);
                        }
                        return -1;
                    }
                } catch (Throwable e) {
                    throw new IOException(e);
                }
            } while (!ˋ);
            throw new EOFException("source exhausted prematurely");
        }
    }

    public final boolean ˋ() throws IOException {
        if (!this.ˎ.needsInput()) {
            return false;
        }
        ॱ();
        if (this.ˎ.getRemaining() != 0) {
            throw new IllegalStateException("?");
        } else if (this.ॱ.ᐝ()) {
            return true;
        } else {
            fxt o_fxt = this.ॱ.ˏ().ॱ;
            this.ˋ = o_fxt.ˋ - o_fxt.ˎ;
            this.ˎ.setInput(o_fxt.ˏ, o_fxt.ˎ, this.ˋ);
            return false;
        }
    }

    private void ॱ() throws IOException {
        if (this.ˋ != 0) {
            int remaining = this.ˋ - this.ˎ.getRemaining();
            this.ˋ -= remaining;
            this.ॱ.ʼ((long) remaining);
        }
    }

    public fxv ˊ() {
        return this.ॱ.ˊ();
    }

    public void close() throws IOException {
        if (!this.ˏ) {
            this.ˎ.end();
            this.ˏ = true;
            this.ॱ.close();
        }
    }
}
